$(function(){
    $('#gores').on('click',function(){
        $('#resForm').show()
        $('#logForm').hide()
    })
    $('#golog').on('click', function () {
        $('#resForm').hide()
        $('#logForm').show()
    })

    layui.form.verify({
        user:[
            /^[a-zA-Z0-9\S]{1,10}$/,
            '账号必须是1-10为非空字符'
        ],
        Pwd:[
            /^[\S]{6,15}$/,
            '密码必须是6-15位非空字符'
        ],
        resPwd:function(value){
            if (value !== $('#resForm [name="password"]').val()){
                return '密码不一致'
            }
        }
    })

    $('#resForm').on('submit',function(e){
        e.preventDefault()
        axios({
            url:'/api/reguser',
            method:'POST',
            data: $(this).serialize()
        }).then(({data:res})=>{
            if(res.status!==0){
                return layer.msg(res.message)
            }
            layer.msg(res.message)
            $('#golog').click()
        })
    })

    $('#logForm').on('submit',function(e){
        e.preventDefault()
        axios({
            url:'/api/login',
            method:'POST',
            data:$(this).serialize()
        }).then(({data:res})=>{
           if(res.status!==0){
               return layer.msg(res.message)
           }
            layer.msg(res.message)
            localStorage.setItem('token',res.token)
            setTimeout(()=>{
               location.href='/index.html'
            },1000)
        })
    })
        
    
})